import { reqCategoryList, reqGetBannerList,reqFloorList} from "@/api";

// home模块小仓库
const state = {
     // namespaced: true,
     // state中数据默认初始值别乱写，服务器返回对象就写对象 服务器返回数组就写数组【根据接口返回值初始化的】
     categoryList: [],
     // 获取轮播图的数据
     bannerList: [] ,
     // 获取floor组件数据
     floorList: []
};
const mutations = {
     CATEGORYLIST(state, categoryList) {
          state.categoryList = categoryList
     },
     BANNERLIST(state,bannerList){
          state.bannerList = bannerList
     },
     GETFLOORLIST(state,floorList) {
          state.floorList = floorList
     }
};
const actions = {
     // 通过API里面的接口 向服务器发送请求 获取服务器的数据
     async categoryList({ commit }) {
          let result = await reqCategoryList()
          if (result.code == 200) {
               commit('CATEGORYLIST', result.data)
          }
     },
     // 获取首页轮播图的接口数据
     async getBannetList({commit}){
       let result = await reqGetBannerList()
          if(result.code==200){
               commit('BANNERLIST',result.data)
          }
     }, 
     // 获取floor接口数据
     async getFloorList({commit}){
          let result = await reqFloorList()
          if(result.code == 200){
               // 提交给mutation
               commit('GETFLOORLIST',result.data)
          }
     }

};
// 计算属性
const getters = {}

export default {
     actions,
     mutations,
     state,
     getters
}